{
  lib,
  config,
  pkgs,
  ...
}:
with lib; let
  cfg = config.modules.nvim;
  # Source my theme
  jabuti-nvim = pkgs.vimUtils.buildVimPlugin {
    name = "jabuti-nvim";
    src = pkgs.fetchFromGitHub {
      owner = "jabuti-theme";
      repo = "jabuti-nvim";
      rev = "17f1b94cbf1871a89cdc264e4a8a2b3b4f7c76d2";
      sha256 = "sha256-iPjwx/rTd98LUPK1MUfqKXZhQ5NmKx/rN8RX1PIuDFA=";
    };
  };
  modus-theme-vim = pkgs.vimUtils.buildVimPlugin {
    name = "modus-theme-vim";
    src = pkgs.fetchFromGitHub {
      owner = "ishan9299";
      repo = "modus-theme-vim";
      rev = "4d827fbf1aad55f4d62225f7b999efc5023864a3";
      sha256 = "7qb0c235YD5IiN3voaK1a/3B7Dl62RbgbmbZ/fzTVhU=";
    };
  };
in {
  options.modules.nvim = {enable = mkEnableOption "nvim";};
  config = mkIf cfg.enable {
    home.file.".config/nvim/settings.lua".source = ./init.lua;

    home.packages = with pkgs; [
      luajit
      lua-language-server
      stylua # Lua
    ];

    programs.bash = {
      initExtra = ''
        export EDITOR="nvim"
      '';

      shellAliases = {
        v = "nvim -i NONE";
        nvim = "nvim -i NONE";
      };
    };

    programs.neovim = {
      enable = true;
      plugins = with pkgs.vimPlugins; [
        vim-nix
        plenary-nvim
        {
          plugin = modus-theme-vim;
          config = "colorscheme modus-vivendi";
        }
        {
          plugin = impatient-nvim;
          config = "lua require('impatient')";
        }
        {
          plugin = lualine-nvim;
          config = "lua require('lualine').setup()";
        }
        {
          plugin = telescope-nvim;
          config = "lua require('telescope').setup()";
        }
        {
          plugin = indent-blankline-nvim;
          config = "lua require('indent_blankline').setup()";
        }
        {
          plugin = nvim-lspconfig;
          config = ''
            lua << EOF
            require('lspconfig').rust_analyzer.setup{}
            require('lspconfig').lua_ls.setup{}
            require('lspconfig').rnix.setup{}
            EOF
          '';
        }
        {
          plugin = nvim-treesitter;
          config = ''
            lua << EOF
            require('nvim-treesitter.configs').setup {
                highlight = {
                    enable = true,
                    additional_vim_regex_highlighting = false,
                },
            }
            EOF
          '';
        }
      ];

      extraConfig = ''
        luafile ~/.config/nvim/settings.lua
      '';
    };
  };
}
